package com.github.edu.repair.manager.service.impl;

import com.fasterxml.jackson.core.type.TypeReference;
import com.github.admin.edu.assembly.common.entity.JsonEntity;
import com.github.admin.edu.assembly.common.util.JsonUtils;
import com.github.admin.edu.assembly.common.util.ObjectUtil;
import com.github.admin.edu.assembly.string.util.StringUtils;
import com.github.admin.edu.orm.serivce.impl.DataRestfulAbstractBaseService;
import com.github.edu.repair.manager.domain.BxsqServerDomain;
import com.github.edu.repair.manager.entity.TBxBxsq;
import com.github.edu.repair.manager.service.BxsqServerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.lang.reflect.Field;

/**
 * Create by IntelliJ IDEA
 * 用户：王建
 * 日期：2018-8-23
 */
@Service
@Slf4j
public class BxsqServerServiceImpl extends DataRestfulAbstractBaseService<TBxBxsq,Long> implements BxsqServerService {

    @Autowired
    private BxsqServerDomain domain;


    @Override
    public String getAllGetEntity(String title, Integer current, Integer rows, String order, String fileId) {
        TBxBxsq tSysUser=new TBxBxsq();
        if(StringUtils.isNotBlank(title)){
            tSysUser.setBxsj(title);
        }
        return super.getAllGetEntity(tSysUser,current,rows,order,fileId);
    }

    @Override
    public String getAllEntity(String title, String order, String fileId) {
        return getAllGetEntity(title,0,0,order,fileId);
    }

    @Transactional
    @Override
    public String saveOrUpdate(String jsonEntity) {
        if(StringUtils.isNotBlank(jsonEntity)){
            JsonEntity<TBxBxsq> tJsonEntity= JsonUtils.toCollection(jsonEntity, new TypeReference<JsonEntity<TBxBxsq>>() {
            });
            TBxBxsq t=tJsonEntity.getData();
            if(null==t.getId()){
                t.setId(sequenceService.getUserId(TBxBxsq.class.getSimpleName()));
            }
            t=domain.save(t);
            tJsonEntity.setData(t);
            return JsonUtils.toJson(tJsonEntity);
        }
        return JsonUtils.toJson(new JsonEntity<TBxBxsq>("保存对象为空！"));
    }

    @Transactional
    @Override
    public String delete(String ids) {
        return super.delete(ids,"Long");
    }

    @Override
    public String getALLPostByPager(String jsonEntity) {
        if(StringUtils.isNotBlank(jsonEntity)){
            JsonEntity<TBxBxsq> tJsonEntity= JsonUtils.toCollection(jsonEntity, new TypeReference<JsonEntity<TBxBxsq>>() {
            });
            if(null!=tJsonEntity){
                return super.getALLPostByPager(tJsonEntity.getData(),tJsonEntity.getPager());
            }
        }
        return JsonUtils.toJson(new JsonEntity<TBxBxsq>("未找到参数！"));
    }
}
